<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>记账簿</title>
<!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/handlebars.min.js" type="text/javascript"></script>
<script src="libs/d3.v3.min.js" type="text/javascript"></script>
<script src="libs/nv.d3.min.js" type="text/javascript"></script>
<link href="libs/bootstrap-3.3.6/css/nv.d3.min.css" rel="stylesheet">
<script src="libs/getQueryString.js" type="text/javascript"></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>个人账册</strong>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-8">
				<ul class="nav nav-pills">
					<li><a href="index.html">首页</a></li>
					<li><a href="shouru.html">新加收入</a></li>
					<li><a href="zhichu.html">新加支出</a></li>
					<li class="active"><a href="query.html">查询</a></li>
					<li><a href="tongji.html">统计</a></li>
					<li><a href="#">用户：<span id="nickname"></span></a></li>
				    <button id="tuichu">用户退出</button>
				</ul>
			</div>
			<div class="col-md-offset-11">
				<ul class="nav nav-pills">
					<li>
						<button id="cleanCookie" class="btn btn-primary btn-block">
							<strong>退出</strong>
						</button>
					</li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-5">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<strong><p>查询结果</p></strong>
					</div>
					<div class="panel-body" id="list"></div>
				</div>
				<button id="delete" class="btn btn-primary btn-block">删除</button>
			</div>
		</div>
	</div>
	<script type="text/x-handlebars-template" id="template">
{{#each item}}
<div class="panel panel-default col-md-5">
  <div class="panel-body">
  <dl>
  <dt>时间</dt><dd>{{date_time}}</dd>
  <dt>地点</dt><dd>{{place}}</dd>
  <dt>类别</dt><dd>{{kind}}</dd>
  <dt>收入金额</dt><dd>{{money_in}}</dd>
  <dt>支付金额</dt><dd>{{money_out}}</dd>
  <dt>备注</dt><dd>{{remark}}</dd>
  </dl>
  </div>
</div>
{{/each}}
</script>
	<script type="text/javascript">
		$(function() {
			var id = getQueryString('id');
			var url = 'queryxq.action?id=' + id;
			$.getJSON(url, function(res) {
				var data = {
					'item' : res
				};
				var t = Handlebars.compile($('#template').html());
				$('#list').html(t(data));

			});
			$('#delete').click(function() {
				$.post('delete.action', {
					id : id
				}, function(res, status) {
					if ("OK" == res) {
						window.location.href = 'index.html';
					}
				})

			})
			$('#tuichu').click(function() {
				$.post('tuichu.action', function(res, status) {
					if ('OK' == res) {
						alert('退出成功');
					}
					window.location.href = "login.html";
				});
			});
			
			$.getJSON('queryUsers.action', function(res) {
				//console.log(res);
				$('#nickname').text(res.nk);
			})

		})
	</script>
</body>
</html>